<?php
require_once 'Zend/Loader.php';

abstract class Service_Condition
{
    /**
     * @var Service_DataSource
     */
    protected $_ds;

    protected $_params = array();

    public function __construct(array $params)
    {
        $this->_params = $params;
    }

    /**
     * Sets a data source.
     *
     * @param Service_DataSource $ds
     * @return Service_Condition
     */
    public function setDataSource($ds)
    {
        $this->_ds = $ds;
        return $this;
    }

    /**
     * Gets a data source.
     *
     * @return Service_Condition
     */
    public function getDataSource()
    {
        return $this->_ds;
    }

    public function __sleep()
    {
        if ($this->_ds instanceof Service_DataSource) {
            $this->_ds = $this->_ds->getName();
        }

        return array('_ds', '_params');
    }

    public function __wakeup()
    {
        if (is_string($this->_ds) && strlen($this->_ds)) {
            Service_DataConnection::getConnection($this->_ds);
        }
    }

    /**
     * Converts condition to string.
     *
     * @return string
     */
    abstract public function __toString();
}